﻿function HidePopupWindow() {
    if (document.getElementById("dvContainer") != undefined) {
        var divtemp = document.getElementById("dvContainer");
        divtemp.parentNode.removeChild(divtemp);
        var divback = document.getElementById("dvBackground");
        divback.parentNode.removeChild(divback);
    }
}
var AlertCust = function (src, Firstmsg, SecondMsg, IconType, PromptType, OnOk, OnCancel) {
    try {
       
        HidePopupWindow();
        var dvContainer = document.createElement("div");
        dvContainer.setAttribute("class", "DivContainerAlert");
        dvContainer.setAttribute("id", "dvContainer");

        var dvBody = document.createElement("div");
        dvBody.setAttribute("style", "line:height:25px;");

        var tbl = $('<table style="min-width:300px;"></table>').attr({ id: "bob" });

        var row = $('<tr style="border-bottom:1px solid black;background-color:Gray;color:white;"></tr>').appendTo(tbl); //first Row
        var tdIcon = $('<td></td>').attr({ valign: "top" });
        var imgname = ImageName(IconType);
        ($('<img></img>').attr({ src: "img/" + imgname })).appendTo(tdIcon);
        tdIcon.appendTo(row); //Icon


        $('<td></td>').html(Firstmsg).attr({ style: "font-weight: bold;line:height:25px;" }).appendTo(row);

//        var tdIcon1 = $('<td style="cursor:pointer;"></td>').attr({ valign: "top" });

//        ($('<img id="img1" onclick="HidePopupWindow();"></img>').attr({ src: "img/remove.gif" })).appendTo(tdIcon1);


//        tdIcon1.appendTo(row); //Icon


        if (SecondMsg != null && SecondMsg.length > 0) {
            row = $('<tr></tr>').appendTo(tbl); //Second Row
            $('<td></td>').attr({ valign: "top" }).appendTo(row);
            $('<td></td>').html('<br/>' + SecondMsg).attr({ style: "line:height:25px;" }).appendTo(row);
        }
        tbl.appendTo(dvBody);
        dvContainer.appendChild(dvBody);

        var dvFooter = document.createElement("div");
        dvFooter.setAttribute("class", "DivFooterAlert");

        switch (PromptType) {
            case 1:
                var element = document.createElement("input");
                element.type = "button";
                element.value = "Ok";
                element.name = "Ok";
                element.setAttribute("class", "AlertButtons");
                element.onclick = function () {
                    HidePopupWindow();
                    if (OnOk != null)
                        setTimeout(OnOk, 0);

                };
                dvFooter.appendChild(element);
                break;
            case 2:
                var element = document.createElement("input");
                element.type = "button";
                element.value = "Ok";
                element.name = "Ok";
                element.setAttribute("class", "AlertButtons");
                element.onclick = function () {
                    HidePopupWindow();
                    if (OnOk != null)
                        setTimeout(OnOk, 0);
                    else {
                        if (src != null) {
                            src["onclick"] = "";
                            src.click();
                        }
                    }
                };

                dvFooter.appendChild(element);
                break;
            case 3:
                var element = document.createElement("input");
                element.type = "button";
                element.value = "Ok";
                element.name = "Ok";
                element.setAttribute("class", "AlertButtons");
                element.onclick = function () {
                    HidePopupWindow();
                    if (OnOk != null)
                        setTimeout(OnOk, 0);
                    else {
                        if (src != null) {
                            src["onclick"] = "";
                            src.click();
                        }
                    }
                };

                dvFooter.appendChild(element);
                var elementCancel = document.createElement("input");
                elementCancel.type = "button";
                elementCancel.value = "Cancel";
                elementCancel.setAttribute("class", "AlertButtons");
                elementCancel.name = "Cancel";
                elementCancel.onclick = function () {
                    HidePopupWindow();
                    if (OnCancel != null)
                        setInterval(OnCancel, 0);
                };
                dvFooter.appendChild(elementCancel);
                break;
            case 4:
                var element = document.createElement("input");
                element.type = "button";
                element.value = "Yes";
                element.name = "Yes";
                element.setAttribute("class", "AlertButtons");
                element.onclick = function () {
                    HidePopupWindow();
                    if (OnOk != null)
                        setTimeout(OnOk, 0);
                    else {
                        if (src != null) {
                            src["onclick"] = "";
                            src.click();
                        }
                    }
                };

                dvFooter.appendChild(element);
                var elementCancel = document.createElement("input");
                elementCancel.type = "button";
                elementCancel.value = "No";
                elementCancel.setAttribute("class", "AlertButtons");
                elementCancel.name = "No";
                elementCancel.onclick = function () {
                    HidePopupWindow();
                    if (OnCancel != null)
                        setTimeout(OnCancel, 0);
                };
                dvFooter.appendChild(elementCancel);
                break;
            default:
                ($('<input></input>').attr({ type: "button", value: "Ok" })).appendTo(dvFooter);
        }

        dvContainer.appendChild(dvFooter);
        document.body.appendChild(dvContainer);
        var dvBackground = document.createElement("div");
        dvBackground.setAttribute("id", "dvBackground");
        dvBackground.setAttribute("style", "z-index: 99999;top:0px; position:fixed; height:100%;width:100%;background-color:gray; opacity:0.5;filter:Alpha(opacity=50); ")
        document.body.appendChild(dvBackground);


    } catch (e) {
        alert(e);
    }
};
var ImageName = function (IconType) {
    var imgname = "exclamation-button.png";
    switch (IconType) {
        case 1:
            imgname = "error.png";
            break;
        case 2:
            imgname = "exclamation-button.png";
            break;
        case 3:
            imgname = "information.png";
            break;
        default:
            imgname = "exclamation-button.png";
    }
    return imgname;
}
function test() {
    alert('jay jalaram');
    HidePopupWindow();
}
var IconType = { "Error": 1, "Warning": 2, "Information": 3 };
var PromptType = { "Validation": 1, "MessageBox": 2, "OkCancel": 3, "YesNo": 4 };